package com.bzyd.mp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bzyd.mp.datascope.DataScope;
import com.bzyd.mp.model.po.Order;
import com.bzyd.mp.service.OrderService;
import com.bzyd.mp.utils.UserContextUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单表(Order)表控制层
 * 测试数据权限
 *
 * @author makejava
 * @since 2022-04-02 00:35:26
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private UserContextUtil userContextUtil;

    /**
     * 模拟登录不同的用户
     *
     * @return
     */
    @GetMapping("/setUser/{userName}")
    public Object setUser(@PathVariable("userName") String userName) {
        userContextUtil.setUser(userName);
        return "ok";
    }

    /**
     * 测试数据权限
     *
     * @return
     */
    //注意：使用此注意后 改接口下的所有查询数据库的语句都会被拦截
    //所以：要么直接单表查询直接返回
    //要么，再Service层方法中使用
    //@DataScope
    //@DataScope(mode = "own_child_dept")
    @DataScope(mode = "custom")
    @GetMapping("/findOrder")
    public Object findOrder() {
        Page<Order> page = new Page<>(1, 20);
        page = orderService.page(page);
        return page;
    }

    /**
     * 演示和PageHelper一起使用时的
     */
    @DataScope(mode = "custom")
    @GetMapping("/pageQuery/{currentPage}/{pageSize}")
    public Object pageQuery(@PathVariable("currentPage") Integer currentPage,
                            @PathVariable("pageSize") Integer pageSize) {
        return orderService.pageQuery(currentPage, pageSize);
    }

}

